package com.adjy.pathbuilders.objects.button;

import com.adjy.pathbuilders.objects.button.listeners.ButtonListener;
import com.adjy.pathbuilders.rendering.DisplayConverter;
import com.adjy.pathbuilders.rendering.GameCanvas;
import com.adjy.pathbuilders.rendering.loading.WeakReferenceBitmap;

public class ImageButton extends Button {
	
	private WeakReferenceBitmap selectedImage;
	private WeakReferenceBitmap unselectedImage;

	/**
	 * Creates a ImageButton based on the given position and Images<br>
	 * This constructor automatically converts to screen resolution based on DisplayConverter
	 * 
	 * @param x
	 *            X - Position
	 * @param y
	 *            Y - Position
	 * @param listener
	 *            ButtonListener to be called when the button is clicked
	 * @param selectedImage
	 *            Selected Image for the Button
	 * @param unselectedImage
	 *            Unselected Image for the Button
	 */
	public ImageButton(float x, float y, ButtonListener listener,
			WeakReferenceBitmap selectedImage, WeakReferenceBitmap unselectedImage) {
		super(x * DisplayConverter.getScreenRatioWidth(),
			  y * DisplayConverter.getScreenRatioHeight(),
			  selectedImage.getBitmap().getWidth(),
			  selectedImage.getBitmap().getHeight(), listener);
		this.selectedImage = selectedImage;
		this.unselectedImage = unselectedImage;
	}

	@Override
	public void render(GameCanvas canvas, float timeElapsed) {
		if (isSelected) {
			canvas.drawBitmap(selectedImage.getBitmap(), x, y);
		} else {
			canvas.drawBitmap(unselectedImage.getBitmap(), x, y);
		}
	}
	
	public void setSelectedImage(WeakReferenceBitmap selectedImage) {
		this.selectedImage = selectedImage;
	}
	
	public void setUnselectedImage(WeakReferenceBitmap unselectedImage) {
		this.unselectedImage = unselectedImage;
	}
}
